package com.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class MyBatisUtils {
	public MyBatisUtils() {
	}

	public static SqlSession getSqlSession(){
		String resource = "conf.xml";
		Reader reader = null;
		SqlSessionFactory sessionFactory = null;
		try {
			reader = Resources.getResourceAsReader(resource);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(reader!=null){
			sessionFactory=new SqlSessionFactoryBuilder().build(reader);
		}
		
		return sessionFactory.openSession();
	}
}
